<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '推广统计';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="channel-visit-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <ul class="nav nav-tabs" role="tablist" style="margin-bottom:15px;">
        <li <?= $_GET['time_type']=='day'?'class="active"':'' ?> >
            <a href="/admin/channel-visit?time_type=day">按天展示</a></li>
        <li <?= $_GET['time_type']=='month'?'class="active"':'' ?> >
            <a href="/admin/channel-visit?time_type=month">按月展示</a></li>
        <li <?= $_GET['time_type']=='year'?'class="active"':'' ?> >
            <a href="/admin/channel-visit?time_type=year">按年展示</a></li>
    </ul>

    <form class="form col-md-1" >
        <input type="hidden" name="time_type" value="<?= $_GET['time_type'] ?>" />
        <label>要查询的条数:</label>
        <input class="form-control col-md-1" type="number" value="<?= $_GET['data_size'] ?>" name="data_size" min="1" max="100" />
    </form>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [

            [
                'attribute'=>'date',
                'label' => '日期',
            ],

            [
                'attribute'=>'jump_count',
                'label' => '从cn跳转',
            ],

            [
                'attribute'=>'visit_count',
                'label' => '访问量',
            ],

            [
                'attribute'=>'down_count',
                'label' => '下载量',
            ],

            [
                'attribute'=>'conversion',
                'label' => '转化率',
                'format' => ['raw',],
                'content' => function($model){
                    return $model['conversion'].'%';
                }
            ],

            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{view}',
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        $time_type = $_GET['time_type'] ?? 'day';
                        $date = $model['date'];
                        return Html::a(' 详情 ',
                            "/admin/channel-visit/detail?time_type=$time_type&date=$date",
                            ['title' => '按渠道查看'] );
                    },
                ],
            ],
        ],
    ]); ?>
</div>
